#include "versioninfo.h"
#include "common/bch.h"
#include "common/stringutils.h"

#include <bitset>
#include <string>

#include <QDebug>

namespace qrcode{

VersionInfo::VersionInfo()
{

}

void VersionInfo::Creator()
{
    //1.基础版本信息
    std::vector<int> info = GetInitInfo();
    //StringUtils::PRINT("版本信息：", info);

    //2.计算纠错码
    BCH *qbch = new BCH();
    std::vector<int> ecc = qbch->Encoding18_6(info);

    //3.将版本信息与纠错码连接
    ConnectBits(info, ecc);
    StringUtils::PRINT("版本信息数据位流：", info);

    versionbitstream = info;
}

std::vector<int> VersionInfo::GetInitInfo()
{
    std::bitset<6> bits = version;
    std::string str = bits.to_string();
    std::vector<int> vec;
    for(int i = 0; i < str.length(); i++){
        vec.push_back(StringUtils::ToInt(str.at(i)));
    }

    return vec;
}

void VersionInfo::ConnectBits(std::vector<int> &vec, std::vector<int> &vec1)
{
    for(int i = 0; i < vec1.size(); i++){
        vec.push_back(vec1.at(i));
    }
}

void VersionInfo::setVersion(int value)
{
    version = value;
}

std::vector<int> VersionInfo::getVersionbitstream() const
{
    return versionbitstream;
}



}
